﻿import request from '/@/utils/request';
import other from '/@/utils/other';
import { AxiosResponse } from 'axios';
import { ISysVisitorReason, ISysVisitorReasonView, ISysVisitorReasonVm } from '/@/views/visitor/sysvisitorreason/api/interface';

interface ISysVisitorReasonApi {
	search(data: object): Promise<AxiosResponse<ISysVisitorReasonView[]>>;

	get(id: string | number): Promise<AxiosResponse<ISysVisitorReasonVm>>;

	add(data: ISysVisitorReasonVm): Promise<AxiosResponse<ISysVisitorReason>>;

	edit(data: ISysVisitorReasonVm): Promise<AxiosResponse<ISysVisitorReason>>;

	batchEdit(data: object): Promise<AxiosResponse>;

	delete(ids: (string | number)[]): Promise<AxiosResponse<number>>;

	export(data: object): Promise<void>;

	exportById(ids: (string | number)[]): Promise<void>;

	import(data: object): Promise<AxiosResponse<number>>;

	approve(data: object, tag: string): Promise<AxiosResponse<any, any>>;
}

function SysVisitorReasonApi(): ISysVisitorReasonApi {
	return {
		async search(data: object): Promise<AxiosResponse<ISysVisitorReasonView[]>> {
			return await request({
				url: '/api/SysVisitorReason/Search',
				method: 'post',
				data,
			});
		},
		async get(id: string | number): Promise<AxiosResponse<ISysVisitorReasonVm>> {
			return await request({
				url: `/api/SysVisitorReason/${id}`,
				method: 'get',
			});
		},
		async add(data: ISysVisitorReasonVm): Promise<AxiosResponse<ISysVisitorReason>> {
			return await request({
				url: '/api/SysVisitorReason/Add',
				method: 'post',
				data,
			});
		},
		async edit(data: ISysVisitorReasonVm): Promise<AxiosResponse<ISysVisitorReason>> {
			return await request({
				url: '/api/SysVisitorReason/Edit',
				method: 'put',
				data,
			});
		},
		async batchEdit(data: object): Promise<AxiosResponse> {
			return await request({
				url: '/api/SysVisitorReason/batchEdit',
				method: 'post',
				data,
			});
		},
		async delete(ids: (string | number)[]): Promise<AxiosResponse<number>> {
			return await request({
				url: '/api/SysVisitorReason/BatchDelete',
				method: 'post',
				data: ids,
			});
		},
		async export(data: object): Promise<void> {
			const response = await request<any, Blob>({
				responseType: 'blob',
				url: '/api/SysVisitorReason/ExportExcel',
				method: 'post',
				data,
			});
			other.downloadFile(response);
		},
		async exportById(ids: (string | number)[]): Promise<void> {
			const response = await request<any, Blob>({
				responseType: 'blob',
				url: '/api/SysVisitorReason/ExportExcelByIds',
				method: 'post',
				data: ids,
			});
			other.downloadFile(response);
		},
		async import(data: object): Promise<AxiosResponse<number>> {
			return await request({
				url: '/api/SysVisitorReason/Import',
				method: 'post',
				data,
			});
		},
		async approve(data: object, tag: string) {
			return request({
				url: '/api/SysVisitorReason/approve?tag=' + tag,
				method: 'post',
				data,
			});
		},
	};
}

export { SysVisitorReasonApi };
